package amd.core.data;

import java.util.ArrayList;

/**
 * @version 1.0
 * @created 18-Mei-2009 4:40:40
 */

public class ListDocWeight extends ArrayList<DocWeight>{

    public void add(ListDocWeight listDocWeight){
        int i=0;
        while(i<listDocWeight.size()){
            add(listDocWeight.get(i));
            i++;
        }
    }

    @Override
    public boolean add(DocWeight docWeight){
        add(docWeight.getIdDoc(), docWeight.getWeight());
        return true;
    }

	/**
	 * 
	 * @param docName, weight
	 */
	public void add(String docName, float weight){
        int i = 0;
        int tokenSize = 0;
        boolean isFound = false;
        DocWeight wd;

        if(isEmpty()){
            super.add(new DocWeight(docName, weight));
        }
        else{
            tokenSize = this.size();
            while(i<tokenSize){
                wd = (DocWeight) get(i);
                if(docName.equalsIgnoreCase(wd.getIdDoc())){
                    set(i, new DocWeight(wd.getIdDoc(), wd.getWeight() + weight));
                    i = size();
                    isFound = true;
                }
                else{
                    i++;
                }
            }
            if(!isFound){
                super.add(new DocWeight(docName, weight));
            }
        }
	}

}